﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using System.Linq.Expressions;
using Bookkeeping.Core.Infrastructure.Reflection;

namespace Bookkeeping.Persistence.Utilities.Extensions
{
    public class LambdaRestriction
    {
        public static SimpleExpression Eq<T>(Expression<Func<T, object>> expression, object value)
        {
            var propertyReader = new PropertyReader<T>(expression);
            return Restrictions.Eq(propertyReader.PropertyName, value);
        }

        public static AbstractCriterion Between<T>(Expression<Func<T, object>> expression, object lo, object hi)
        {
            var propertyReader = new PropertyReader<T>(expression);
            return Restrictions.Between(propertyReader.PropertyName, lo, hi);
        }
    }
}
